/**************************************************************
 *@ProjectName: blweibo
 *@FileName: HomeListBaseActivity.java
 *@Date: 2011-5-31
 *@Copyright: 2011 www.hrbanlv.com Inc. All rights reserved.
 **************************************************************/
package com.zhiweibo;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;

/**
 * The Class HomeListBaseActivity.
 * 
 * @author SunHaibin
 * @since Android 1.6
 * @history 2011-5-31
 */
public abstract class HomeListBaseActivity extends BaseActivity {

    /*
     * (non-Javadoc)
     * 
     * @see com.yingnet.zhiweibo.BaseActivity#handleTitleBarEvent(int)
     */
    @Override
    protected abstract void handleTitleBarEvent(int paramInt);

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
     */
    @Override
    public boolean onCreateOptionsMenu(Menu paramMenu) {
        getMenuInflater().inflate(R.menu.main, paramMenu);
        return true;
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem paramMenuItem) {
        MainTabActivity mParent = (MainTabActivity) getParent();
        switch (paramMenuItem.getItemId()) {
        default:
            return true;
        case R.id.main_about:
            startActivity(new Intent(this, AboutActivity.class));
            return true;
        case R.id.main_feedback:
            startActivity(new Intent(this, EditActivity.class).putExtra("mode", 4).putExtra("content", "#Android意见反馈#"));
            return true;
        case R.id.main_switchuser:
            mParent.startActivity(new Intent(this, AccountManager.class));
            return true;
        case R.id.main_officialweibo:
            startActivity(new Intent(this, GFActivity.class));
            return true;
        case R.id.main_settings:
            startActivity(new Intent(this, SettingsPref.class));
            return true;
        case R.id.main_search:
            new AlertDialog.Builder(this).setTitle(R.string.exit_confirm).setIcon(R.drawable.ic_help)
                    .setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                            finish();
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                            paramDialogInterface.cancel();
                        }
                    }).show();
            return true;
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
     */
    @Override
    public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent) {
        if (paramInt == KeyEvent.KEYCODE_BACK) {
            new AlertDialog.Builder(this).setTitle(R.string.exit_confirm).setIcon(R.drawable.ic_help)
                    .setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                            finish();
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                            paramDialogInterface.cancel();
                        }
                    }).show();
            return true;
        } else {
            return super.onKeyDown(paramInt, paramKeyEvent);
        }
    }
}
